<template>
	<view>
		<u-empty
		        mode="coupon"
		        icon="http://cdn.uviewui.com/uview/empty/coupon.png"
				v-if="userCouponInfoList.length==0"
		>
		</u-empty>
		<block v-for="(item,k) in userCouponInfoList" :key="k">
			<view class="juan flex align-center">
				<view class="u-p-l-20 u-p-t-32 u-p-b-32" style="width: 500rpx;">
					<view class="text-bold text-bold ">{{item.couponInfo.title}}</view>
					<view class="u-font-24 u-m-t-10 text999">{{item.couponInfo.outTime}}到期</view>
					<view class="flex align-center u-m-t-10">
						<view class="u-font-24 text999 u-m-r-10">{{item.couponInfo.type==0?'洗衣券':'商城券'}}</view>
						<!-- <u-icon name="arrow-down-fill" size="10" color="#999999"></u-icon> -->
					</view>
				</view>
				<view class="flex align-center justify-center flex-direction" style="width: 190rpx;height: 100%;">
					<view class="">
						<text class="price "
							:class="item.couponInfo.fullSub>orderAmount?'text-expire':''">{{item.couponInfo.amount}}</text>
						<text class="u-font-24" :class="item.couponInfo.fullSub>orderAmount?'text-expire':''"
							style="color: #FF2E3F;">元</text>
					</view>
					<view class="u-font-22" :class="item.couponInfo.fullSub>orderAmount?'text-expire':''"
						style="color: #FF2E3F;">满{{item.couponInfo.fullSub}}元可用</view>

					<view class="btn" :class="item.couponInfo.fullSub>orderAmount?'btn-bg':''"
						@click="handleGoBack(item)">
						{{item.couponInfo.fullSub>orderAmount?'不可用':'使用'}}
					</view>


				</view>
			</view>
		</block>

	</view>
</template>

<script>
	import {
		getCouponInfoList,
		getUserCouponInfoList,
		userGetCouponInfo
	} from '@/common/api/api.js'
	export default {
		data() {
			return {
				activeStyle: {
					color: '#FF5B00',
				},
				tabs: [{
					name: '未领取',
					status: "-1"
				}, {
					name: '未使用',
					status: "0"
				}, {
					name: '已使用',
					status: "1"
				}, {
					name: '已到期',
					status: "2"
				}],
				couponInfoList: [], // 优惠券列表
				userInfoId: '',
				tabItem: {
					index: 0,
					name: ''
				},
				userCouponInfoList: [], // 用户优惠券
				index: 0,
				orderAmount: 0.00
			}
		},
		onLoad(options) {
			console.log("options", options)
			this.orderAmount = options.fullSub;
			this.handleGetUserCouponInfoList(options);
			this.userInfoId = this.$store.state.$token;
		},
		methods: {
			// 获取用户优惠券
			handleGetUserCouponInfoList(item) {
				getUserCouponInfoList({
					userInfoId: this.$store.state.$token,
					status: 0,
					type: item.type,
					fullSub: this.orderAmount
				}).then(res => {
					this.userCouponInfoList = res.data.list;
				})
			},
			// 选中优惠券后的跳转
			handleGoBack(item) {
				if (item.fullSub < this.orderAmount) {
					// 返回时传递数据
					uni.navigateBack({
						delta: 1,
						success: () => {
							uni.$emit('back', item.id)
						}
					})
				}
			}



		}
	}
</script>

<style lang="scss">
	.juan {
		margin-top: 20rpx;
		margin-left: 32rpx;
		margin-right: 32rpx;
		width: 686rpx;
		height: 186rpx;
		background: #FFFFFF;
		border-radius: 8rpx;
		background-image: url('/static/personal/coupon-juan.png');
		background-size: 100% 100%;

		.price {
			font-size: 52rpx;
			font-family: D-DIN DIN-Bold, D-DIN DIN;
			font-weight: bold;
			color: #FF2E3F;
		}

		.btn {
			width: 120rpx;
			height: 48rpx;
			line-height: 48rpx;
			text-align: center;
			color: #fff;
			background: linear-gradient(90deg, #FE5C32 0%, #FF2F40 100%);
			border-radius: 30rpx;
			margin-top: 6rpx;
		}
	}

	.rlus {
		width: 686rpx;
		height: 160rpx;
		background: #FAFAFA;
		margin-left: 32rpx;
		margin-right: 32rpx;
	}

	.text-expire {
		color: #D3D6E6 !important;
	}

	.btn-bg {
		background: #D3D6E6 !important;
		color: #fff;
	}
</style>